/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package onlinestore.GUI;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 *
 * @author Li
 */
public class SORFile {
    public void saveToFile(String s)
    {
        try
        {
            //"searchItem.txt"
            FileWriter searchItem = new FileWriter("searchItem.txt");
            BufferedWriter bf = new BufferedWriter(searchItem);
            bf.write(s);
            bf.flush();
            bf.close();
            searchItem.close();

            System.out.println("- "+s+" -"+" is saved.");
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }

    public String readFromFiile()
    {
        String s = null;
        try {
            File searchItem = new File("searchItem.txt");
            BufferedReader br = new BufferedReader(new FileReader(searchItem));
            s = br.readLine();
        } catch (Exception e) {
            System.out.println("Error : "+e);
        }
        return s;
    }

}
